home *** CD-ROM | disk | FTP | other *** search
/ C & C++ Multimedia Cyber Classroom / C and C++ Multimedia Cyber Classroom (Prentice Hall) (1998).iso / src / fig10_01.jar / Ch10 / Fig10_01 / Hourly1.cpp < prev    next >
C/C++ Source or Header  |  1997-10-28  |  1KB  |  40 lines

  1. // Fig. 10.1: hourly1.cpp
  2. // Member function definitions for class HourlyWorker
  3. #include <iostream.h>
  4. #include "hourly1.h"
  5.  
  6. // Constructor for class HourlyWorker
  7. HourlyWorker::HourlyWorker( const char *first, 
  8.                             const char *last,
  9.                             double w, double h )
  10.    : Employee( first, last )   // call base-class constructor
  11. {
  12.    setWage( w );
  13.    setHours( h );
  14. }
  15.  
  16. // Set the wage
  17. void HourlyWorker::setWage( double w ) 
  18.    { wage = w > 0 ? w : 0; }
  19.  
  20. // Set the hours worked
  21. void HourlyWorker::setHours( double h )
  22.    { hours = h >= 0 && h < 168 ? h : 0; }
  23.  
  24. // Get the HourlyWorker's pay
  25. double HourlyWorker::earnings() const 
  26.    if ( hours <= 40 ) // no overtime
  27.       return wage * hours;
  28.    else               // overtime is paid at wage * 1.5
  29.       return 40 * wage + ( hours - 40 ) * wage * 1.5;
  30. }
  31.  
  32. // Print the HourlyWorker's name 
  33. void HourlyWorker::print() const
  34. {
  35.    cout << "\n    Hourly worker: ";
  36.    Employee::print();
  37. }
  38.  
  39.